<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <!-- <a-form-item label="公司">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder="" v-model="pageData.firm"
                @press-enter="huiche" />
            </a-form-item> -->
            <CorporateSectorCascader :configCascader="configCascader" @changeCascader="changeCascader" />
            <!-- <a-form-item label="物料名称">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""
                v-model="pageData.materialName" @press-enter="huiche" />
            </a-form-item> -->
            <a-form-item label="领料单号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder="" v-model="pageData.code1"
                @press-enter="huiche" />
            </a-form-item>
          </a-form>
        </div>
        <!-- <div class="my-tool-bar"> -->
        <Toolbar :items="tabTtpe == 1 ? [
          `${permissionStore.hasPermisson('wjlllb.cx') ? '查询' : ''}`,
          `${permissionStore.hasPermisson('wjlllb.xz') ? '新增' : ''}`,
          `${permissionStore.hasPermisson('wjlllb.sc') ? '删除' : ''}`,
          '打印二维码', '审核',
        ] : ['查询']" @add="addHandler" @del="deleteHandler" @select="selectHandler" @export="exports" @audit="audits"
          @printQRCode="printQRCode" @counter="counters">
        </Toolbar>
        <!-- <Toolbar style="float:right" v-else-if="isIDs == 2" :items="" @select="selectHandler1"
           >
          </Toolbar> -->
        <!-- </div> -->
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18" />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" @change="changeTabs">
        <a-tab-pane title="待审核" :key="1">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
            :suppressDragLeaveHidesColumns="true" rowSelection="multiple" @grid-ready="gridReady"
            style="height: calc(100% - 45px);" @columnResized="onColumnResized" @columnMoved="onColumnMoved"
            @columnVisible="onColumnVisible" :defaultColDef="defaultColDef" class="ag-theme-alpine"
            :rowData="table.dataList" :localeText="localeText1" :columnDefs="tc"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size
            @change="PageSize" @page-size-change="change1" style="justify-content: center" :page-size="size"
            :current="page" />
        </a-tab-pane>
        <a-tab-pane title="已审核" :key="2">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
            :suppressDragLeaveHidesColumns="true" style="height: calc(100% - 45px);" :defaultColDef="defaultColDef"
            @grid-ready="gridReady1" class='ag-theme-alpine' :rowData="tableDataList" :columnDefs="tc"
            :localeText="localeText1">
          </AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total1" show-total show-jumper show-page-size
            @change="PageSize" @page-size-change="change1" style="justify-content: center" :page-size="size1"
            :current="page1" />
        </a-tab-pane>
      </a-tabs>
    </template>
    <el-dialog v-model="dblclicksShow" :width="1300" draggable>
      <template #title>
        <center><b style="font-size: 22px; color: red">{{ pageData.sideTitle }}</b></center>
      </template>
      <div>
        <!-- <el-scrollbar> -->
        <a-form ref="formRef" layout="inline" :model="searchData">
          <a-form-item label="公司">
            <a-input popup-container="html" disabled :style="{ width: '10rem' }" v-model="searchData.firm"
              class="bacClass" />
          </a-form-item>
          <a-form-item label="部门">
            <a-input popup-container="html" disabled :style="{ width: '10rem' }" v-model="searchData.department"
              class="bacClass" />
          </a-form-item>
          <a-form-item label="仓库">
            <a-input popup-container="html" disabled :style="{ width: '10rem' }" v-model="searchData.wh"
              class="bacClass" />
          </a-form-item>
          <a-form-item label="需求时间">
            <a-date-picker popup-container="html" disabled :style="{ width: '10rem' }"
              v-model="searchData.requisitionTime" class="bacClass" />
          </a-form-item>
          <a-form-item label="领料单号">
            <a-input popup-container="html" disabled :style="{ width: '10rem' }" v-model="searchData.pickCode"
              class="bacClass" />
          </a-form-item>
        </a-form>
        <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
          @grid-ready="gridReady2" style="height:50vh" :defaultColDef="defaultColDef2" class='ag-theme-alpine'
          :rowData="pageData.list" :columnDefs="tableColumnsWlss" :localeText="localeText1">
        </AgGridVuesCopys>
      </div>
      <template #footer>
        <el-button size="large" type="info" @click="() => (dblclicksShow = false)">关闭</el-button>
      </template>
    </el-dialog>
    <a-drawer ok-text="保存" cancel-text="关闭" :drawer-style="{ zIndex: 999 }" :mask-closable="false" unmount-on-close
      popup-container=".arco-tabs-content" height="100%" :visible="pageData.showAdd" @ok="sideOk"
      :ok-loading="pageData.pageLoading" placement="bottom" @cancel="pageData.showAdd = false">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <!-- <el-scrollbar> -->
        <a-form ref="formRef" layout="inline" :model="searchData" size="mini">
          <a-form-item label="公司" field="firmId" :rules="[{ required: true, message: '公司必填' }]">
            <a-cascader v-model="searchData.firmId" :options="pageData.firmGroupList" allow-clear ref="casOb"
              @change="companyChange" :style="{ width: '10rem ' }"
              :class="{ bacClass: !(pageData.sideTitle != '新增五金领料单据') }" :title="pageData.title"
              :disabled="pageData.sideTitle != '新增五金领料单据'" popup-container="html" />
          </a-form-item>
          <a-form-item label="部门" :rules="[{ required: true, message: '部门必填' }]" field="depId">
            <a-cascader v-model="searchData.depId" :options="pageData.bmList" allow-clear ref="casc"
              :class="{ bacClass: !(searchData.firmId == null || searchData.firmId == '') }" :title="pageData.title1"
              :style="{ width: '10rem' }" popup-container="html" />
          </a-form-item>
          <a-form-item label="仓库" :rules="[{ required: true, message: '仓库必填' }]" field="wh">
            <a-select popup-container="html" :style="{ width: '10rem' }" v-model="searchData.wh" allow-clear :disabled="pageData.sideTitle != '新增五金领料单据' ||
              searchData.firmId == '' ||
              searchData.firmId == undefined ||
              searchData.firmId == null
              " :class="{
    bacClass: !(
      searchData.firmId == null ||
      searchData.firmId == '' ||
      pageData.sideTitle != '新增五金领料单据'
    ),
  }">
              <a-option v-for="item in whList" :value="item.id">
                {{ item.warehouseName }}
              </a-option>
            </a-select>
          </a-form-item>
          <a-form-item label="需求时间" :rules="[{ required: true, message: '需求时间' }]" field="requisitionTime">
            <a-date-picker popup-container="html" :style="{ width: '10rem' }" v-model="searchData.requisitionTime"
              disabled class="bacClass" />
          </a-form-item>
          <a-form-item label="领料单号">
            <a-input popup-container="html" disabled :style="{ width: '10rem' }" v-model="searchData.pickCode"
              class="bacClass" />
          </a-form-item>
        </a-form>

        <a-space style="margin-bottom: 10px">
          <a-button type="primary" @click="addLine" size="mini">新增</a-button>
          <a-button type="primary" @click="delLine" size="mini">删除</a-button>
        </a-space>
        <!-- <a-table stripe :bordered="true" :columns="tableColumnsWl" size="mini"
            :row-selection="{ showCheckedAll: true, width: 50 }" v-model:selected-keys="selectedRowKeysWl"
            :loading="table.tableLoading" :data="pageData.list" rowKey="id">
            <template #oldNewNum="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.oldNewNum" class="input-demo bacClass" :disabled="record.oldNewService != 1 || (record.oldNewService == 1 && !record.num)
                  " :min="0" :max="record.num" @input="oldNewNumImput($event, record)"
                  :precision="record.unit == '重量' ? 2 : 0" />
              </div>
            </template>
            <template #oldNewService="{ record }">
              <el-checkbox v-model="record.oldNewService" disabled :true-label="1" :false-label="0"></el-checkbox>
            </template>
            <template #num="{ record }">
              <div style="width: 100%">
                <a-input-number v-model="record.num" class="input-demo bacClass" :min="0" :max="100000"
                  :precision="record.unit == '重量' ? 2 : 0" />
              </div>
            </template>
            <template #deviceCode="{ record }">
              <div style="width: 100%">
                <a-input v-model="record.deviceCode" class="input-demo bacClass"></a-input>
              </div>
            </template>
          </a-table> -->
        <!-- </el-scrollbar> -->
        <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
          @grid-ready="gridReady2" style="height:71vh" :defaultColDef="defaultColDef2" class='ag-theme-alpine'
          :rowData="pageData.list" :columnDefs="tableColumnsWlss" :localeText="localeText1">
        </AgGridVuesCopys>
        <!-- <paginationCopys :page-size-options="pagingList1" :total="total1" show-total show-jumper show-page-size
                        @change="PageSize" @page-size-change="change" style="justify-content: center"
                        :page-size="pagination.pageSize" :current="pagination.page" /> -->
      </div>
    </a-drawer>
    <a-modal v-model:visible="visible" @ok="handleOK" @cancel="handleCancel">
      <template #title> 选择部门 </template>
      <a-form ref="formRef1" layout="inline" :model="searchData" size="mini">
        <a-form-item label="部门" :rules="[{ required: true, message: '部门必填' }]" field="depId">
          <!-- <a-select popup-container="html"  :style="{ width: '15rem' }" @change="companyChange" v-model="searchData.depId" allow-clear
                        @focus="foucusUseFrim(2)">
                        <a-option v-for="item in pageData.bmList" :value="item.id">
                            {{ item['department'] }}
                        </a-option>
                    </a-select> -->
          <a-cascader v-model="searchData.depId" :options="pageData.bmList" allow-clear ref="casc"
            :class="{ bacClass: !(searchData.firmId == null || searchData.firmId == '') }" :title="pageData.title1"
            popup-container="html" />
        </a-form-item>
        <!-- <a-form-item label="组别" field="groupId">
                                    <a-select popup-container="html"  :style="{ width: '15rem' }" @change="companyChange" v-model="searchData.groupId" allow-clear
                                        @focus="foucusUseFrim(3)">
                                        <a-option v-for="item in pageData.zuList" :value="item.id">
                                            {{ item['zu'] }}
                                        </a-option>
                                    </a-select>
                                </a-form-item> -->
      </a-form>
    </a-modal>

    <a-modal fullscreen v-model:visible="visibleYl" :on-before-ok="handleOks" @cancel="handleCancels">
      <template #title>五金仓库存</template>
      <template #footer>
        <a-button size="mini" @click="handleCancels"> 取消 </a-button>
        <a-button type="primary" size="mini" @click="handleOks"> 确认 </a-button>
      </template>
      <whTable ref="whTbRef" :whId="whIds" :urlSelect="urlSelects" @getRowData="getRowDatas"></whTable>
    </a-modal>
    <a-modal :visible="visible2" @ok="handleOk" @cancel="visible2 = false" okText="打印" cancelText="关闭" unmountOnClose>
      <template #title> 打印二维码 </template>
      <div id="lllist" style="height: 500px">
        <div v-for="(item, index) in qrDataList" :key="index" style="display: inline-block; margin-bottom: 10px">
          <QrcodeVue :value="item['code1']"></QrcodeVue>
          <div style="display: inline-block; vertical-align: top; margin-left: 15px; width: 250px">
            <span>领料单号: {{ decodeURI(item['code']) }}</span>
            <br />
          </div>
        </div>
      </div>
    </a-modal>
  </pageTabelLayout>
</template>

<script lang="ts">
import { post } from '@/api/http'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'
import emitter from '@/hooks/useEventBus'
import { ref, reactive, onMounted, toRefs } from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import { Button, Form, Message, Modal } from '@arco-design/web-vue'
import { FormInstance } from '@arco-design/web-vue/es/form'
import { baseURL } from '@/api/axios.config'
import axios from 'axios'
import filedownload from 'js-file-download'
import usePermission from '@/store/modules/permission'
import PageTabelLayout from '@/components/pageTabelLayout.vue'
import whTable from '@/views/wh/components/wjKcSelect/index.vue'

import WHStore from '@/store/modules/wh'
import WHService from '@/service/wh'

import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import printJS from 'print-js'
import QrcodeVue from 'qrcode.vue'
import dayjs from 'dayjs'
import { pagingList } from '@/api/paging'
import { slicing } from '@/utils/caseFrimAndSecRig'

// 引入

import { localeText } from '@/api/aggridZw'
import { keyBy } from 'lodash'
import { number } from 'echarts'
import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
interface HardwarePickList {
  id: any
  firm: any
  firmId: any
  warehouseId: any
  warehouseName: string | undefined
  depId: any
  department: any
  materialL: any
  materialM: any
  materialS: any
  materialCode: any
  materialName: any
  num: any
  unit: any
  infoState: any
  obsoleteState: any
  createName: string | undefined
  createTime: string | undefined
  updateName: string | undefined
  updateTime: string | undefined
  firmTypeId: any
  totalNum: any
  grade: any
  oldNewService: any
}

export default {
  name: 'HardwarePickList',

  setup() {
    const permissionStore: any = usePermission()
    const casc = ref()
    const total = ref(0)
    const total1 = ref(0)
    const page = ref(1)
    const page1 = ref(1)
    const size = ref(10)
    const size1 = ref(10)
    const searchData = reactive<{
      whTypeName: string
      firmId: any
      wh: any
      firm: string
      firmTypeId: any
      department: any
      depId: any
      groupId: any
      groupName: any
      createName: any
      createTime: any
      requisitionTime: any
      pickCode: any
    }>({
      whTypeName: '',
      firmId: null,
      wh: '',
      firm: '',
      firmTypeId: null,
      department: '',
      depId: null,
      groupId: null,
      groupName: '',
      createName: '',
      createTime: '',
      requisitionTime: '',
      pickCode: ''
    })
    const whStore = WHStore()
    whStore.getWhTypeList()
    function PageSize(val: any) {
      if (tabTtpe.value == 1) {
        page.value = val
        doRefresh()
      } else {
        page1.value = val
        doRefresh1();
      }
    }
    function change1(val: any) {
      if (tabTtpe.value == 1) {
        size.value = val
        doRefresh()
      } else {
        size1.value = val
        doRefresh1();
      }
    }
    const headerShow = ref<boolean>(true)
    // 重构后的未审核页面查询方法
    function doRefresh() {
      pageData.pageLoading = true
      updateGridState01()
      post({
        url: 'wms/IronwarePick/getPage',
        data: {
          page: page.value,
          size: size.value,
          auditState: 0,
          companyId: pageData.firmId,
          pickCode: pageData.code1,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            data.list.forEach(function (o: any) {
              getTotalNum(o)
            })
            table.handleSuccess(data.list)
            // 查询方法改
            gridOption.value.setRowData(data.list)

            total.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }
    // 重构后的已审核页面查询方法
    function doRefresh1() {
      pageData.pageLoading = true
      post({
        url: 'wms/IronwarePick/getPage',
        data: {
          page: page1.value,
          size: size1.value,
          auditState: 1,
          companyId: pageData.firmId,
          pickCode: pageData.code1,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {

            // table.handleSuccess(data.list)
            // 查询方法改
            tableDataList.value = data.list
            gridOption1.value.setRowData(data.list)
            total1.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }
    // 之前的查询方法
    // function doRefresh() {
    //   pageData.pageLoading = true
    //   updateGridState01()
    //   post({
    //     url: 'wms/metalsRequisitionForm/getPage',
    //     data: {
    //       page: page.value,
    //       size: size.value,
    //       deleteState: '0',
    //       materialName: pageData.materialName,
    //       firmId: pageData.firmId,
    //       code: pageData.code1,
    //     },
    //   })
    //     .then(({ data, code }: any) => {
    //       if (code === 200) {
    //         data.list.forEach(function (o: any) {
    //           getTotalNum(o)
    //         })
    //         table.handleSuccess(data.list)

    //         // 查询方法改

    //         gridOption.value.setRowData(data.list)

    //         total.value = data.total
    //       }
    //     })
    //     .catch(console.log)
    //     .finally(() => {
    //       pageData.pageLoading = false
    //     })
    // }

    const { selectedRowKeys, onSelectionChange } = useRowSelection()
    const selectedRowKeysWl = ref()
    const pagination = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('id')
    const tableColumns = useTableColumn([
      {
        title: '领料单号',
        key: 'pickCode',
        dataIndex: 'pickCode',
        width: 150,
      },
      {
        title: '公司',
        key: 'companyName',
        dataIndex: 'companyName',
        width: 150,
      },

      {
        title: '部门',
        key: 'departmentName',
        dataIndex: 'departmentName',
        width: 150,
      },
      {
        title: '领料时间',
        key: 'pickDate',
        dataIndex: 'pickDate',
        width: 150,
      },
      {
        title: '仓库名称',
        key: 'warehouseName',
        dataIndex: 'warehouseName',
        width: 150,
      },
      {
        title: '创建人',
        key: 'createName',
        dataIndex: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        key: 'createTime',
        dataIndex: 'createTime',
        width: 200,
      },
      {
        title: '最后修改人',
        key: 'updateName',
        dataIndex: 'updateName',
        width: 150,
      },
      {
        title: '最后修改时间',
        key: 'updateTime',
        dataIndex: 'updateTime',
        width: 200,
      },
      {
        title: '审核状态',
        key: 'auditState',
        dataIndex: 'auditState',
        width: 150,
        fixed: 'right',
        slotName: 'auditState',
      },

      {
        title: '操作',
        key: 'id',
        slotName: 'act',
        width: 150,
        fixed: 'right',
      },
    ])

    const tableColumnsWlss = [
      {
        showRowGroup: 'hide_def',
        "headerName": "",
        "checkboxSelection": true,
        "headerCheckboxSelection": true,
        "pinned": "left",
        "width": 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: "left",
      },
      // {
      //   headerName: '部门',
      //   field: 'department',
      //   width: 150,
      // },
      {
        headerName: '物料大类',
        field: 'bigClassName',
        width: 150,
      },
      {
        headerName: '物料中类',
        field: 'middleClassName',
        width: 150,
      },
      {
        headerName: '物料小类',
        field: 'subClassName',
        width: 150,
      },
      {
        headerName: '物料编号',
        field: 'materialCode',
        width: 150,
      },
      {
        headerName: '物料名称',
        field: 'materialName',
        width: 150,
      },
      {
        headerName: '等级',
        field: 'grade',
        width: 150,
      },
      {
        headerName: '以旧换新',
        field: 'oldNewService',
        width: 150,
        cellRenderer: {
          template: `<a-checkbox v-model="val" disabled></a-checkbox>`,
          setup(props: any) {
            let val = ref()
            val.value =
              props.params.data.oldNewService == null
                ? false
                : props.params.data.oldNewService == 1
                  ? true
                  : false
            return {
              val,
            }
          },
        }
      },
      {
        headerName: '单位',
        field: 'unit',
        width: 150,
      },
      {
        headerName: '规格',
        field: 'materialSpec',
        width: 150,
      },
      {
        headerName: '库存数量',
        field: 'stockNum',
        width: 150,
      },
      {
        headerName: '数量',
        field: 'num',
        width: 150,
        cellRenderer: {
          template: `
                   <div><a-input-number v-model="res.num" class="bacClass" :min="0" :max="100000"></a-input-number></div>
            `,
          setup(props: any) {
            const res = ref(props.params.data)
            return {
              res,
              // e: pageData.isSataus
            }
          }
        }
      },
      {
        headerName: '单价',
        field: 'price',
        width: 150,
      },
      {
        headerName: '以旧换新数量',
        field: 'oldNewNum',
        width: 150,
        cellRenderer: {
          template: `
          <div><a-input-number v-model="res.oldNewNum" class="bacClass" :min="0" :max="res.num" @input="oldNewNumImput($event, res)"
                  :precision="res.unit == '重量' ? 2 : 0" :disabled="oldNewService != 1 || (oldNewService == 1 && !res.num)"></a-input-number></div>
            `,
          setup(props: any) {
            const res = ref(props.params.data)
            const oldNewNumImput = (value: any, col: any) => {
              // console.log(value)
              // console.log(col)
              if (value > col.num) {
                Message.warning('以旧换新数量不能大于领料数量')
                setTimeout(function () {
                  col.oldNewNum = col.num
                }, 100)
              }
            }
            return {
              res,
              oldNewNumImput,
              oldNewService: props.params.data.oldNewService,
              // e: pageData.isSataus
            }
          }
        }
      },
      {
        headerName: '是否固定资产',
        field: 'fixAssetStatus',
        width: 150,
        cellRenderer: {
          template: `<a-checkbox v-model="val" disabled></a-checkbox>`,
          setup(props: any) {
            let val = ref()
            val.value =
              props.params.data.fixAssetStatus == null
                ? false
                : props.params.data.fixAssetStatus == 1
                  ? true
                  : false
            return {
              val,
            }
          },
        }
      },
      {
        headerName: '设备编号',
        field: 'deviceCode',
        width: 150,
        cellRenderer: {
          template: `
          <div><a-input v-model="res.deviceCode" class="bacClass"></a-input></div>
            `,
          setup(props: any) {
            const res = ref(props.params.data)
            return {
              res,
              // e: pageData.isSataus
            }
          }
        }
      },
    ]

    let tc: any[] = tableColumns.map((o) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
      }
      obj['width'] = '250px'
      if (o.slotName === 'act') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = '80px'
        obj['cellRenderer'] = {
          template: `<a-space>
            <el-button style="color:#165dff;" @click="a" class="gesture" link v-if="e ==1">修改</el-button>
            <el-button style="color:#165dff;" @click="b" class="gesture" link v-else-if="e==2">详情</el-button>
          </a-space>`,
          setup(props: any) {
            const a = () => {
              editHandler(props.params.data)
            }
            const b = () => {
              editHandler1(props.params.data)
            }
            return {
              e: pageData.isEdit,
              a,
              b,
              c: props.params.data.infoState,
              e1: permissionStore.hasPermisson('wjlllb.xg'),
            }
          },
        }
      }

      if (o.slotName === 'auditState') {
        obj['resizable'] = false

        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = '90px'
        obj['cellRenderer'] = {
          template: `<a-space>
            <el-tag type="warning" class="gesture" v-if="e==1">待审核</el-tag>
            <el-tag type="success" class="gesture" v-else-if="e==2" >已审核</el-tag>
            </a-space>`,
          setup(props: any) {
            // let val = ref()
            // if (props.params.data.infoState == 0) {
            //   val.value = '待处理'
            // } else if (props.params.data.infoState == 1) {
            //   val.value = '已受理'
            // } else if (props.params.data.infoState == 2) {
            //   val.value = '已完结'
            // }

            return {
              // val,
              e: pageData.isEdit,
            }
          },
        }
        //     obj['filterParams'] = {
        //   valueFormatter: function (params: any) {
        //     return params.value == '0'
        //       ? '待处理'
        //       : params.value == '1'
        //       ? '已受理'
        //       : params.value == '2'
        //       ? '已完结'
        //       : ''
        //   },
        // }
      }
      // if (o.slotName === 'oldNewService') {
      //   obj['filter'] = false
      //   obj['cellRenderer'] = {
      //     template: `<div><a-checkbox v-model="val" disabled></a-checkbox></div>`,
      //     setup(props: any) {
      //       let val = ref()
      //       val.value =
      //         props.params.data.oldNewService == null
      //           ? false
      //           : props.params.data.oldNewService == 1
      //             ? true
      //             : false
      //       return {
      //         val,
      //       }
      //     },
      //   }
      // }

      return obj
    })

    let a = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tc = a.concat(tc)
    const pageData = reactive<{
      showAdd: boolean
      sideTitle: string
      dropDownData: any
      nameList: []
      pageLoading: boolean
      typeList: []
      dropDownData1: any
      rHeight: any
      isEdit: any
      firmGroupList: any[]
      wlList: any[]
      list: any[]
      wlListL: any[]
      wlListS: any[]
      bmList: any[]
      zuList: any[]
      firm: any
      firmId: any
      materialName: any
      title: any
      title1: any
      wlList1: any[]
      djList: any[]
      code: any
      code1: any
      isSataus: boolean
    }>({
      isSataus: false,
      nameList: [],
      showAdd: false,
      sideTitle: '新增五金领料单据',
      dropDownData: '',
      pageLoading: false,
      typeList: [],
      dropDownData1: '',
      rHeight: 0,
      isEdit: 1,
      firmGroupList: [],
      wlList: [],
      list: [],
      wlListL: [],
      wlListS: [],
      bmList: [],
      zuList: [],
      firm: '',
      firmId: null,
      materialName: '',
      title: '',
      title1: '',
      wlList1: [],
      djList: [],
      code: '',
      code1: '',
    })

    //下拉框得到焦点
    const focusSel = () => {
      getBigClass({ bigClassName: '', deleteState: 0 })
    }
    //下拉数据
    const options = ref<any>(pageData.wlListL)
    const loading = ref(false)
    const handleSearch = (value: any) => {
      if (value) {
        const ob = { bigClassName: value, deleteState: 0 }
        loading.value = true
        getBigClass(ob)
        options.value = pageData.wlListL
        loading.value = false
      } else {
        options.value = []
      }
    }

    //查询物料大类
    function getBigClass(val: any) {
      post({
        url: 'purchase/MaterialBigClass/getFieldValue',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.wlListL = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }

    onMounted(() => {
      doRefresh()
      //弹出层的高
      if (pageData.rHeight !== undefined) {
        pageData.rHeight = pageData.rHeight - 100
      }
      window.addEventListener('resize', () => {
        pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
        //弹出层的高
        if (pageData.rHeight !== undefined) {
          pageData.rHeight = pageData.rHeight - 100
        }
      })
    })
    //查询
    const selectHandler = () => {
      if (tabTtpe.value == 1) {
        page.value = 1
        doRefresh()
      } else {
        page1.value = 1
        doRefresh1()
      }
    }
    const selectHandler1 = () => {
      page1.value = 1
      doRefresh1()
    }
    const queryData = reactive({
      clothType: '',
    })
    const addHandler = async () => {
      for (var key in searchData) {
        if (key == 'requisitionTime') {
          searchData[key] = dayjs().format('YYYY-MM-DD')
        } else {
          searchData[key] = ''
        }
      }
      for (var key in dataForm) {
        dataForm[key] = ''
      }
      pageData.list = []
      await getFirmGroup()
      post({
        url: '/admin/acl/user/findUserToken',
      }).then((res) => {
        post({
          url: 'admin/acl/user/findUserToken',
          data: {
            name: res,
          },
        }).then((res: any) => {
          if (res.code === 200) {
            searchData.firmId = res.data.data.firmId
            searchData.depId = res.data.data.departmentId
            companyChange()
            getBmGroup(res.data.data.firmId)
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            })
          }
        })

      })
      post({
        url: 'wms/IronwarePick/getCodeGenerate',
        data: {},
      }).then((res: any) => {
        if (res.code === 200) {
          searchData.pickCode = res.data
        }
      })
      pageData.showAdd = true
      pageData.sideTitle = '新增五金领料单据'
    }
    const dataForm = reactive<HardwarePickList>({
      id: undefined,
      firmId: undefined,
      warehouseId: undefined,
      warehouseName: undefined,
      depId: undefined,
      department: undefined,
      materialL: undefined,
      materialM: undefined,
      materialS: undefined,
      materialCode: undefined,
      materialName: undefined,
      num: undefined,
      unit: undefined,
      infoState: undefined,
      obsoleteState: undefined,
      createName: undefined,
      createTime: undefined,
      updateName: undefined,
      updateTime: undefined,
      firm: undefined,
      firmTypeId: undefined,
      totalNum: 0,
      grade: '',
      oldNewService: 0,
    })

    // 表格准备事件
    const gridOption = ref()
    const colState = ref()
    const gridReady = (params: any) => {
      gridOption.value = params.api
      colState.value = params.columnApi
      // console.log('colState.value', colState.value)
      // console.log('tableColumns', tableColumns)
      // console.log('tc', tc)
    }
    const tableDataList: any = ref([])
    const gridOption1 = ref()
    const colState1 = ref()
    const gridReady1 = (params: any) => {
      gridOption1.value = params.api
      colState1.value = params.columnApi
    }

    let formRef = ref<FormInstance>()
    let formRef1 = ref<FormInstance>()
    const sideOk = () => {
      if (pageData.list.length == 0) {
        Message.warning({
          content: '请新增至少一条物料信息',
          duration: 5000,
        })
        return
      }
      formRef.value?.validate().then((err) => {
        if (!err) {
          //拿到仓库名称
          let list = whList.value.filter(function (o: any) {
            return o['id'] == searchData.wh
          })
          let warehouseName = ''
          if (list.length > 0) {
            warehouseName = list[0]['warehouseName']
          }
          let flag = false
          pageData.list.forEach(function (o: any) {
            // o.whTypeName = searchData.whTypeName
            // o.firmId = searchData.firmId
            // o.firm = searchData.firm
            // o.firmTypeId = searchData.firmTypeId
            // o['requisitionTime'] = searchData['requisitionTime']
            // o.depId = searchData.depId
            // o.groupId = searchData.groupId
            // o.groupName = searchData.groupName
            // o.createName = searchData.createName
            // o.createTime = searchData.createTime
            // o['warehouseName'] = warehouseName
            // o['warehouseId'] = searchData.wh
            // o['code'] = pageData.code
            if (o['num'] == null || o['num'] == 0) {
              flag = true
            }
          })
          let dataMap = {}
          dataMap['departmentId'] = searchData.depId
          dataMap['departmentName'] = searchData.department
          // dataMap['groupId'] = searchData.groupId
          // dataMap['groupName'] = searchData.groupName
          dataMap['companyId'] = searchData.firmId
          dataMap['companyName'] = searchData.firm
          dataMap['pickDate'] = searchData.requisitionTime
          dataMap['warehouseId'] = searchData.wh
          dataMap['warehouseName'] = warehouseName
          dataMap['pickCode'] = searchData.pickCode
          dataMap['IronwarePickDetail'] = pageData.list

          if (flag) {
            Message.warning({
              content: '请填写数量,数量不可为0!',
              duration: 5000,
            })
            return
          }
          // pageData.list.forEach(function (o: any) {
          //   if ((o['id'] + '').indexOf('add') != -1) {
          //     o['id'] = null
          //   }
          // })
          pageData.pageLoading = true
          if (pageData.sideTitle === '新增五金领料单据') {
            // post({
            //   url: '/wms/metalsRequisitionForm/add',
            //   data: pageData.list,
            // })
            //   .then((res: any) => {
            //     if (res.code === 200) {
            //       formRef.value?.resetFields()
            //       pageData.showAdd = false

            //       Message.success({
            //         content: '新增成功',
            //         duration: 5000,
            //       })
            //     } else {
            //       Message.error({
            //         content: res.message,
            //         duration: 5000,
            //       })
            //     }
            //     doRefresh()
            //   })
            // 重构后的新增保存方法

            post({
              url: 'wms/IronwarePick/insertList ',
              data: dataMap,
            })
              .then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  pageData.showAdd = false
                  // pageData.isSataus = false
                  Message.success({
                    content: '新增成功',
                    duration: 5000,
                  })
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
                doRefresh()
              })
              .finally(() => {
                doRefresh()
                pageData.pageLoading = false
              })
          } else {
            dataMap['id'] = pageData.code
            post({
              url: 'wms/IronwarePick/updateList',
              data: dataMap,
            })
              .then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  pageData.showAdd = false
                  // pageData.isSataus = false
                  Message.success({
                    content: '修改成功',
                    duration: 5000,
                  })
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              })
              .finally(() => {
                doRefresh()
                pageData.pageLoading = false
              })
          }
        }
      })
    }
    const deleteHandler = () => {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      }

      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk() {
          pageData.pageLoading = true
          post({
            url: 'wms/IronwarePick/delete',
            data: gridOption.value.getSelectedRows().map((o: any) => {
              return o.id
            }),
          })
            .then(({ code, data }: any) => {
              if (code === 200) {
                Message.success({
                  content: '删除成功',
                  duration: 5000,
                })
                pagination.page = 1
                doRefresh()
              } else {
                Message.error({
                  content: '删除失败',
                  duration: 5000,
                })
              }
            })
            .finally(() => {
              pageData.pageLoading = false
            })
        },
      })
    }

    const editHandler = (record: HardwarePickList) => {
      // selCxAll1({ bigClassName: '' })
      // getBigClass({ bigClassName: '' })

      // whService.getWarhouseListByFirmId(record.firmId, '五金仓')
      // whList.value = whService.whList.value

      // searchData.wh = record['warehouseId']
      // getFirmGroup()
      // getBmGroup(record.firmId)
      // pageData.code = record['code']
      for (var key in record) {
        searchData[key] = record[key]
      }
      searchData.depId = record['departmentId']
      searchData.firmId = record['companyId']
      searchData.firm = record['companyName']
      searchData.requisitionTime = record['pickDate']
      searchData.wh = record['warehouseId']
      searchData.department = record['departmentName']
      pageData.code = record['id']
      getFirmGroup()
      getBmGroup(searchData.firmId)
      whService.getWarhouseListByFirmId(searchData.firmId, '五金仓')
      //根据单号回显此单号的物料信息
      // post({
      //   url: 'wms/metalsRequisitionForm/getList',
      //   data: { code: record['code'] },
      // })
      //   .then(({ code, data, message }: any) => {
      //     if (code === 200) {
      //       for (var key in record) {
      //         searchData[key] = record[key]
      //       }

      //       pageData.list = data
      //       pageData.list.forEach(function (o: any) {
      //         getTotalNum(o)
      //       })
      //       record.oldNewService == 0 ? false : record.oldNewService == 1 ? true : 0
      //       pageData.sideTitle = '修改五金领料单据'
      //       pageData.showAdd = true
      //     } else {
      //       Message.error({
      //         content: message,
      //         duration: 5000,
      //       })
      //     }
      //   })
      // 重构后的修改查看明细方法
      post({
        url: 'wms/IronwarePickDetail/getList',
        data: { pickId: record['id'] },
      })
        .then(({ code, data, message }: any) => {
          if (code === 200) {
            pageData.list = data
            // pageData.list.forEach(function (o: any) {
            //   getTotalNum(o)
            // })
            record.oldNewService == 0 ? false : record.oldNewService == 1 ? true : 0
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        .finally(() => {
          pageData.pageLoading = false
        })
      pageData.sideTitle = '修改五金领料单据'
      pageData.showAdd = true
    }
    //详情
    const editHandler1 = (record: HardwarePickList) => {
      for (var key in record) {
        searchData[key] = record[key]
      }
      searchData.firm = record['companyName']
      searchData.requisitionTime = record['pickDate']
      searchData.wh = record['warehouseName']
      searchData.department = record['departmentName']
      post({
        url: 'wms/IronwarePickDetail/getList',
        data: { pickId: record['id'] },
      })
        .then(({ code, data, message }: any) => {
          if (code === 200) {
            pageData.list = data
            record.oldNewService == 0 ? false : record.oldNewService == 1 ? true : 0
          } else {
            Message.error({
              content: message,
              duration: 5000,
            })
          }
        })
        .finally(() => {
          pageData.pageLoading = false
        })
      dblclicksShow.value = true
      // pageData.isSataus = true
      pageData.sideTitle = '五金领料单据详情'
    }

    //导出
    const exports = () => {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return
      } else {
        let idList: any = []
        gridOption.value.getSelectedRows().forEach(function (o: any) {
          idList.push(o['id'])
        })
        //将表头拼接出来
        let head =
          '<th>编号</th><th>品牌名称</th><th>布类类型</th><th>备注</th><th>创建人</th><th>创建时间</th><th>最后修改人</th><th>最后修改时间</th>'
        //拿到当前表格数据与勾选的行做筛选

        let nowRow = table.dataList.filter(function (o) {
          return (
            gridOption.value
              .getSelectedRows()
              .map((o: any) => {
                return o.id
              })
              .indexOf(o['id']) !== -1
          )
        })
        let body = ''
        nowRow.forEach(function (o) {
          body += '<tr><td>' + o['brandCode'] + '</td>'
          body += '<td>' + o['brandName'] + '</td>'
          body += '<td>' + o['clothClass'] + '</td>'
          body += '<td>' + o['remark'] + '</td>'
          body += '<td>' + o['createName'] + '</td>'
          body += '<td>' + o['createTime'] + '</td>'
          body += '<td>' + o['updateName'] + '</td>'
          body += '<td>' + o['updateTime'] + '</td>'
          body += '</tr>'
        })
        tableToXlsx(head, '五金领料单据', body)
      }
    }

    function tableToXlsx(head: any, filename: any, body: any) {
      const uri = 'data:application/vnd.ms-excel;base64,',
        template = `<html>
            <head><meta charset="UTF-8"></head>
            <body><table border="1"><tr>${head}</tr>${body}</table></body>
        </html>`

      const a = document.createElement('a')
      a.href = uri + window.btoa(unescape(encodeURIComponent(template)))
      a.download = filename
      a.click()
      document.removeChild(a)
    }

    //下拉数据
    const options1 = ref<any>(pageData.wlListS)
    const loading1 = ref(false)
    const handleSearch1 = (value: any) => {
      if (value) {
        const ob = {
          bigClassName: value,
        }
        loading.value = true
        selCxAll1(ob)
        options1.value = pageData.wlListS
        loading1.value = false
      } else {
        options1.value = []
      }
    }

    //下拉框查询 物料小类
    function selCxAll1(val: any) {
      // post({
      //   url: 'purchase/MaterialSubClass/getFieldValue',
      //   data: val,
      // }).then(({ data, code }: any) => {
      //   if (code === 200) {
      //     pageData.wlListS = data
      //   } else {
      //     Message.error({
      //       content: '查询失败！',
      //       duration: 5000,
      //     })
      //   }
      // })
    }

    //下拉框得到焦点
    const focusSel1 = () => {
      selCxAll1({ bigClassName: '' })
    }

    const handleChange = (_data: any) => {
      table.handleSuccess(_data)
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
      // flex: 1
    }
    const huiche = () => {
      doRefresh()
    }
    const localeText1: any = ref(localeText)
    let i = 0
    //成分添加一行 点击新增按钮
    const addLine = () => {
      // searchData.depId = ''
      // searchData.department = ''
      // visible.value = true;
      searchData['department'] = slicing(casc.value.selectViewValue[0].label)
      pageData.title1 = slicing(casc.value.selectViewValue[0]['label'])
      //在这个数组前面添加一行
      // pageData.list.unshift({
      //     "id": "add" + (i++),
      //     "materialL": "",
      //     "materialS": "",
      //     "materialCode": "",
      //     "materialName": "",
      //     "num": "",
      //     depId: searchData.depId,
      //     department: searchData.department,
      //     grade: "",
      //     totalNum: "",

      // })
      if (searchData.wh == '' || searchData.wh == null || searchData.wh == undefined) {
        Message.error('请选择仓库')
        return false
      }
      whIds.value = Number(searchData.wh)
      urlSelects.value = 'wms/ironwareStockSummary/getPage'
      whTbRef.value.delWhList()
      visibleYl.value = true
    }

    //成分 删除
    const delLine = () => {
      // if (selectedRowKeysWl.value.length === 0) {
      if (gridOption2.value.getSelectedRows().length === 0) {
        Message.error({
          content: '请先勾选',
          duration: 5000,
        })
        return
      }
      // console.log(pageData['list'], gridOption2.value.getSelectedRows(), '1')
      // pageData['list'] = pageData['list'].filter(function (o: any) {
      //   // return selectedRowKeysWl.value.indexOf(o['id']) === -1
      //   return gridOption2.value.getSelectedRows().indexOf(o['id']) === -1
      // })
      // console.log(pageData['list'], gridOption2.value.getSelectedRows(), '2')
      const selectedRows = gridOption2.value.getSelectedRows();

      pageData['list'] = pageData['list'].filter(o => {
        const materialCode = o['materialCode'];
        const exists = selectedRows.some((row: any) => row['materialCode'] === materialCode);
        return !exists;
      });
    }
    const whService = new WHService()
    const companyList: any = whService.companyList
    const whTypeList = whService.whTypeList
    const whList = ref<any[]>([])
    let casOb = ref()
    // 公司下拉框 改变
    const companyChange = () => {
      searchData.wh = ''
      // whService.getWarhouseListByFirmId(searchData.firmId, '五金仓')
      getBmGroup(searchData.firmId)
      getWarhouseListByFirmId()
      console.log(whList.value)
      setTimeout(function () {
        if (casOb.value.selectViewValue.length != 0) {
          pageData.title = slicing(casOb.value.selectViewValue[0]['label'])
          searchData.firm = slicing(casOb.value.selectViewValue[0]['label'])
        }
      }, 100)
    }
    watch(
      () => whService.whList.value,
      (o, n) => {
        whList.value = whService.whList.value
      }
    )
    //下拉数据
    const options2 = ref<any>(pageData.wlList)
    const handleSearch2 = (value: any) => {
      if (value) {
        const ob = {}
        if (nums == 1) {
          ob['materialCode'] = value
        } else {
          ob['materialName'] = value
        }
        loading.value = true
        getWlName(ob)
        options2.value = pageData.wlListS
        loading.value = false
      } else {
        options2.value = []
      }
    }

    //查询物料名称
    function getWlName(val: any) {
      post({
        url: 'purchase/MaterialInfo/getFieldValueWms',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          if (nums == 1) {
            pageData.wlList1 = data
          } else {
            pageData.wlList = data
          }
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }
    let subClassName = ''
    let nums = 1
    //下拉框得到焦点
    const focusSel2 = (record: any, num: any) => {
      // subClassName = record.materialS
      if (num == 1) {
        getWlName({ materialCode: '' })
      } else {
        getWlName({ materialName: '' })
      }

      nums = num
    }
    //物料名称改变 拿到物料编号
    function changeWl(record: any, val: any) {
      let list2 = pageData.list.filter(function (o: any) {
        return o['materialName'] == record['materialName'] && o['depId'] == record['depId']
      })
      if (list2.length > 1) {
        record['materialName'] = ''
        record['materialCode'] = ''
        record['specification'] = ''
        Message.warning({
          content: '请不要重复选择物料！',
          duration: 5000,
        })
        return
      }

      let list = pageData.wlList.filter(function (o: any) {
        return o['materialName'] == val
      })
      if (list.length > 0) {
        record['materialCode'] = list[0]['materialCode']
        record['unit'] = list[0]['unit']
        record['specification'] = list[0]['specification']
        record['materialL'] = list[0]['materialL']
        record['materialS'] = list[0]['materialS']
      }
      getTotalNum(record)
    }
    //物料编号改变 拿到物料名称
    function changeBh(record: any, val: any) {
      let list2 = pageData.list.filter(function (o: any) {
        return o['materialCode'] == record['materialCode'] && o['depId'] == record['depId']
      })
      if (list2.length > 1) {
        record['materialName'] = ''
        record['materialCode'] = ''
        record['specification'] = ''
        Message.warning({
          content: '请不要重复选择物料！',
          duration: 5000,
        })
        return
      }

      let list = pageData.wlList1.filter(function (o: any) {
        return o['materialCode'] == val
      })
      if (list.length > 0) {
        record['materialName'] = list[0]['materialName']
        record['unit'] = list[0]['unit']
        record['specification'] = list[0]['specification']
        record['materialL'] = list[0]['materialL']
        record['materialS'] = list[0]['materialS']
      }
      getTotalNum(record)
    }
    function changeDj(record: any) {
      getTotalNum(record)
    }

    //拿到库存数量
    function getTotalNum(record: any) {
      // post({
      //   url: 'wms/ironwareStockSummary/getGoodsStockNum',
      //   data: {
      //     materialCode: record['materialCode'],
      //     grade: record['grade'],
      //     warehouseId: record['warehouseId'],
      //   },
      // }).then(({ code, data }) => {
      //   if (code === 200) {
      //     console.log(data)
      //     record['totalNum'] = data['totalNum']
      //   }
      // })
    }
    //部门下拉框弹窗
    const visible = ref(false)
    const handleCancel = () => {
      visible.value = false
    }
    const handleOK = () => {
      formRef1.value?.validate().then((err) => {
        if (!err) {
          // let list = pageData.bmList.filter(function (o: any) {
          //     return o['id'] == searchData['depId']
          // })
          // if (list.length > 0) {
          //     searchData['department'] = list[0]['department']
          // }

          searchData['department'] = slicing(casc.value.selectViewValue[0].label)
          pageData.title1 = slicing(casc.value.selectViewValue[0]['label'])
          //在这个数组前面添加一行
          pageData.list.unshift({
            id: 'add' + i++,
            materialL: '',
            materialS: '',
            materialCode: '',
            materialName: '',
            num: '',
            depId: searchData.depId,
            department: searchData.department,
            grade: '',
            totalNum: '',
          })

          visible.value = false
        }
      })
    }
    //   // 获取公司列表
    const getFirmGroup = () => {
      post({
        url: 'org/baCompany/getTreeCompanyByUser',
        data: {},
      }).then(({ code, data }) => {
        if (code === 200) {
          pageData.firmGroupList = data
        }
      })
    }
    // 获取部门列表
    const getBmGroup = (val: any) => {
      // searchData.depId = ''
      post({
        url: 'org/baCompany/getDepartmentTree?companyId=' + val,
      }).then((result) => {
        if (result.code === 200) {
          pageData.bmList = result.data
        }
      })
    }
    //获取仓库下拉框
    const getWarhouseListByFirmId = () => {
      post({
        url: 'wms/warehouse/getWarehouseByPara',
        data: {
          firmId: searchData.firmId,
          warehouseTypeName: '五金仓',
          virtuallyState: 0,
        },
      }).then(({ code, data }) => {
        if (code === 200) {
          searchData.wh = data.length > 0 ? data[0].id : ''
          whList.value = data
        }
      })
    }

    //取到所有排纱下拉框
    function focusDj() {
      post({
        url: 'dict/dictTypeDetail/getListByCodeType?codeType=26',
      }).then((res: any) => {
        if (res.code == 200) {
          pageData.djList = res.data
        }
      })
    }

    const visibleYl = ref(false)

    const whIds: any = ref(null)
    const urlSelects: any = ref('')
    const whTbRef: any = ref()

    const handleOks = () => {
      // pageData.list.unshift({
      //     "id": "add" + (i++),
      //     "materialL": "",
      //     "materialS": "",
      //     "materialCode": "",
      //     "materialName": "",
      //     "num": "",
      //     depId: searchData.depId,
      //     department: searchData.department,
      //     grade: "",
      //     totalNum: "",

      // })
      // console.log(whListRowData)

      const duplicateObject = whListRowData.find((obj1: any) =>
        pageData.list.some(
          (obj2) => obj1.materialCode === obj2.materialCode && obj1.grade === obj2.grade
        )
      )

      if (duplicateObject) {
        console.log('找到相同的对象：', duplicateObject)
        Message.warning(
          `物料编号：${duplicateObject.materialCode} 以及等级：${duplicateObject.grade} 相同，已在列表中，请重新选择`
        )
        return
      }
      if (whListRowData.length == 0) {
        Message.warning(`请选择一条单据`)
        return
      }
      whListRowData.forEach((e: any) => {
        delete e.id
        e.depId = searchData.depId
        e.department = searchData.department
        e.materialL = e.majorCategory
        e.materialS = e.subCategory
        e.bigClassName = e.majorCategory
        e.middleClassName = e.middleCategory
        e.subClassName = e.subCategory

        e.stockNum = e.totalNum
        e.materialSpec = e.specification
      })
      // console.log(whListRowData)
      pageData.list = [...pageData.list, ...whListRowData]
      visibleYl.value = false

      // return true
    }

    const handleCancels = () => {
      visibleYl.value = false
    }

    let whListRowData: any = []

    const getRowDatas = (e: any) => {
      whListRowData = e
      console.log(e, '1221')
    }

    const qrDataList: any = ref([])

    const visible2 = ref(false)

    const printQRCode = () => {
      qrDataList.value = []
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请勾选需要打印的数据')
        return
      }
      let row = gridOption.value.getSelectedRows()
      row.forEach(function (o: any) {
        let ob: any = {}
        ob['code'] = o['code']
        ob['code1'] = JSON.stringify({ code: o['code'] })
        qrDataList.value.push(ob)
      })
      visible2.value = true
    }

    const handleOk = () => {
      printJS({
        printable: 'lllist',
        type: 'html',
        targetStyles: ['*'],
      })
      visible2.value = false
    }
    const oldNewNumImput = (value: any, col: any) => {
      console.log(value)
      console.log(col)
      if (value > col.num) {
        Message.warning('以旧换新数量不能大于领料数量')
        col.oldNewNum = col.num
      }
    }
    const pagingList1: any = ref(pagingList)
    const configCascader = ref<{}>({
      corporateWidth: '180px', //公司宽度
      sectorWidth: '180px', //部门宽度
      corporateRquired: false, //公司是否必填
      sectorRquired: false, //部门是否必填
      size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
      corporateName: '选择公司', //公司label
      sectorName: '选择部门', //部门label
      cascaderShow: 'sector', //配置部门不显示
    })
    const changeCascader = (data: any) => {
      const { corporateId } = data
      pageData.firmId = corporateId
    }
    const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
      saveOrUpdateGridState01('HardwarePickList', gridOption, colState, tc)
    const onColumnMoved = () => {
      saveGridState01()
    }
    const onColumnResized = () => {
      saveGridState01()
    }
    const onColumnVisible = () => {
      saveGridState01()
    }

    const gridOption2 = ref()
    const gridReady2 = (params: any) => {
      gridOption2.value = params.api
    }
    const defaultColDef2 = {
      sortable: true,
      resizable: true,
      filter: true,
    }
    // const total1 = ref(10);
    // 未审核页面审核方法
    const audits = () => {
      if (gridOption.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return;
      }
      Modal.confirm({
        title: '系统提示',
        content: '是否审核此订单',
        onOk() {
          post({
            url: "wms/IronwarePick/setAudit",
            data: gridOption.value.getSelectedRows().map((item: any) => {
              return { id: item.id, auditState: 1 }
            })
          }).then((res: any) => {
            if (res.code === 200) {
              doRefresh();
              Message.success('审核通过')
              // selectedRowKeys.value = []
            } else {
              Message.error(res.message)
            }
          })
        }
      })
    }
    // 已经审核页面反审方法
    const counters = () => {
      if (gridOption1.value.getSelectedRows().length === 0) {
        Message.error('请先勾选')
        return;
      }
      Modal.confirm({
        title: '系统提示',
        content: '是否审核此订单',
        onOk() {
          post({
            url: "wms/IronwarePick/setAudit",
            // data: auditStateId,
            data: gridOption1.value.getSelectedRows().map((item: any) => {
              return { id: item.id, auditState: 0 }
            })
          }).then((res: any) => {
            if (res.code === 200) {
              doRefresh1();
              Message.success('审核通过')
              // selectedRowKeys.value = []
            } else {
              Message.error(res.message)
            }
          })
        }
      })
    }
    //已处理 未处理tab切换
    const tabTtpe = ref(1);
    const changeTabs = (val: any) => {
      tabTtpe.value = val
      pageData.isEdit = tabTtpe.value
      if (val == 1) {
        doRefresh()
      } else {
        doRefresh1()
      }
    };
    const dblclicksShow = ref(false)
    return {
      gridReady1,
      dblclicksShow,
      tableDataList,
      tabTtpe,
      selectHandler1,
      changeTabs,
      audits,
      counters,
      defaultColDef2,
      total1,
      gridReady2,
      gridOption2,
      saveOrUpdateGridState01,
      saveGridState01,
      updateGridState01,
      onColumnMoved,
      onColumnResized,
      onColumnVisible,
      colState,
      changeCascader,
      configCascader,
      oldNewNumImput,
      pagingList1,
      handleOk,
      visible2,
      qrDataList,
      printQRCode,
      urlSelects,
      getRowDatas,
      whTbRef,
      whIds,
      handleCancels,
      handleOks,
      visibleYl,
      changeDj,
      focusDj,
      changeBh,
      casOb,
      casc,
      handleOK,
      formRef1,
      visible,
      handleCancel,
      changeWl,
      options2,
      handleSearch2,
      focusSel2,
      getWlName,
      getBigClass,
      whList,
      searchData,
      companyList,
      whTypeList,
      companyChange,
      addLine,
      delLine,
      huiche,
      localeText1,
      defaultColDef,
      tc,
      total,
      PageSize,
      change1,
      page,
      size,
      page1,
      size1,
      editHandler,
      editHandler1,
      deleteHandler,
      sideOk,
      formRef,
      dataForm,
      addHandler,
      selectedRowKeys,
      selectedRowKeysWl,
      pagination,
      tableColumns,
      table,
      rowKey,
      pageData,
      queryData,
      selectHandler,
      exports,
      options,
      loading,
      handleSearch,
      focusSel,
      options1,
      loading1,
      handleSearch1,
      focusSel1,
      headerShow,
      handleChange,
      gridReady,
      tableColumnsWlss,
      permissionStore,
    }
  },
  components: { Toolbar, PageTabelLayout, CorporateSectorCascader, whTable, QrcodeVue },
}
</script>
